import { ElMessage } from 'element-plus';
export interface BasicDrawMapProps {
	map?: any;
	isAdd?: Boolean;
	isEdit?: Boolean;
	isDelete?: Boolean;
	showDrawTool?: Boolean;
}
type operateType = 'draw' | 'edit' | 'delete' | 'cancel' | 'deleteLastPoint' | 'over';

export function useDrawMap(options: BasicDrawMapProps) {
	const defaultOptions = {
		isAdd: false,
		isEdit: false,
		isDelete: false,
		showDrawTool: false,
	};
	/**
	 * 合并默认属性配置和自定义属性配置
	 * @param options 默认属性配置对象
	 * @param props 自定义属性配置对象
	 * @returns 合并后的属性配置对象
	 */
	const mergeDefaultOptions = (options: any, props: any): BasicDrawMapProps => {
		for (const key in options) {
			if (!Object.getOwnPropertyDescriptor(props, key)) {
				props[key] = options[key];
			}
		}
		return props;
	};
	//覆盖默认值
	const state = mergeDefaultOptions(defaultOptions, options);
	// 初始化
	const initDrawMap = (map: any) => {
		state.map = map;
		state.map.pm.addControls({
			position: 'topleft',
			drawCircleMarker: false,
			rotateMode: false,
		});
	};

	// const handleOperateBtn = (key: operateType) => {
	// 	switch (key) {
	// 		case 'draw':
	// 			//新增
	// 			if (state.showDrawTool && !state.isAdd) {
	// 				ElMessage.warning('请先取消或完成修改绘制');
	// 				return;
	// 			}
	// 			this.checkLandLayer.clearLayers();
	// 			this.isDelete = false;
	// 			this.isEdit = false;
	// 			if (!this.isAdd) {
	// 				this.isDrawTool = true;
	// 				document.querySelector('.leaflet-draw-draw-polygon').click();
	// 			} else {
	// 				this.cancelDraw();
	// 				this.isDrawTool = false;
	// 			}
	// 			this.isAdd = !this.isAdd;
	// 			break;
	// 	}
	// };
	return { initDrawMap };
}
